package com.luoqian.demo02;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class Demo_01 {

    public static void main(String[] args) throws InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        //获取一个类对象
        Class<User> clazz = User.class;
        System.out.println(clazz.getName());
        System.out.println(clazz.getPackage());
        System.out.println(clazz.getClassLoader());
        System.out.println(clazz.getSuperclass());
        //获取一个对象实例
        User user = clazz.newInstance();
        Method method = clazz.getDeclaredMethod("jump");
        method.setAccessible(true);
        //通过反射执行方法
        method.invoke(user,null);
    }

}
